package esiag.pds.Test;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;

import javolution.util.FastList;

import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import esiag.pds.beans.Information;
import esiag.pds.beans.Parameters;
import esiag.pds.contextManagement.Context;
import esiag.pds.contextManagement.ContextManager;
import esiag.pds.servers.RMIServer;

public class CrashOfServer {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub		
		
		try {
			int x=0;
			 XmlBeanFactory factory=new XmlBeanFactory(new ClassPathResource("Parameters.xml"));
			 Parameters param=factory.getBean("parameters",Parameters.class);
			 
			 ContextManager cm=new ContextManager(param);
			 RMIServer server =new RMIServer(param.getPort());
			
			 FastList<Serializable>l=new FastList();//<>();
				l.add(new Information());
				l.add(new Information());
			Context c =new Context();
			while(x<4){			
				
				c.addList(l);
				cm.setContext(c);
				server.rebind(cm);
				System.out.println("Nombre de liste dans le contexte : "+c.getNbList());
				x+=1;
				Thread.sleep(2000);
			}
			System.out.println("Crash du serveur !!");
			System.exit(0);			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
}
